package com.sistemagestion;


import java.util.List;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.ImageView;
import android.widget.TextView;

public class InicioAdapter extends ArrayAdapter<String>{
	
	private List<String> opciones;
	private int res;
	Context context;
	private Typeface font;
	
	public InicioAdapter(Context context, int textViewResourceId, List<String> objects) {

		super(context, textViewResourceId, objects);
		this.res = textViewResourceId;
		this.opciones = objects;
		this.context = context;
		this.font = Typeface.createFromAsset(context.getAssets(), "fonts/AMETH.TTF");
	}

	@Override
	public void add(String object) {
		opciones.add(object);
	}

	@Override
	public int getCount() {
		return opciones.size();
	}

	@Override
	public Filter getFilter() {
		return super.getFilter();
	}

	@Override
	public String getItem(int position) {
		return opciones.get(position);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewholder;
		if (convertView == null){
			viewholder = new ViewHolder();
			LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(res, null);
			viewholder.lblOperacion = (TextView)convertView.findViewById(R.id.lblOperacion);
			viewholder.imgOperacion = (ImageView)convertView.findViewById(R.id.imgOperacion);
			convertView.setTag(viewholder);
		}
		else{
			viewholder = (ViewHolder)convertView.getTag();
		}
		
		viewholder.lblOperacion.setText((String)getItem(position));
		viewholder.lblOperacion.setTypeface(font);
		
		if (((String)getItem(position)).equals("Clientes"))
			viewholder.imgOperacion.setImageResource(R.drawable.clientes);
		if (((String)getItem(position)).equals("Productos"))
			viewholder.imgOperacion.setImageResource(R.drawable.productos);
		if (((String)getItem(position)).equals("Ventas"))
			viewholder.imgOperacion.setImageResource(R.drawable.ventas);
		
		return convertView;
	}

	private static class ViewHolder{
		ImageView imgOperacion;
		TextView lblOperacion;
	}
	@Override
	public void remove(String object) {
		// TODO Auto-generated method stub
		super.remove(object);
	}

}
